
import {
  ADD_NUMBER,
  SUB_NUMBER,
  INCREMENT,
  DECREMENT,
  BANNERS,
  SET_USERDATA
} from './constants.js';

import defaultState from './state'

// reducer 实际修改数据的地方 
function reducer(state = defaultState, action) {
  switch (action.type) {
    case ADD_NUMBER:
      return { ...state, counter: state.counter + action.num };
    case SUB_NUMBER:
      return { ...state, counter: state.counter - action.num };
    case INCREMENT:
      return { ...state, counter: state.counter + 1 };
    case DECREMENT:
      return { ...state, counter: state.counter - 1 };
    case BANNERS:
      return { ...state, banners: action.banners };

    case SET_USERDATA:
      return { ...state, userdata: action.userdata };

    default:
      return state;
  }
}

export default reducer;
